package com.example.opengldemo.jbulletJava;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.util.Log;

import com.example.opengldemo.R;

import javax.vecmath.Vector3f;

public class Constant    
{
	 final static float TIME_STEP=1.0f/60;
	  final static int MAX_SUB_STEPS=5;
	  final static float EYE_X=-5;
	  final static float EYE_Y=4;
	  final static float EYE_Z=5;
	  final static float TARGET_X=0;
	  final static float TARGET_Y=0;
	  final static float TARGET_Z=0;

    final static float GT_UNIT_SIZE=0.6f;
    
	public static final float UNIT_SIZE=0.5f;
	public static final float LAND_HIGHEST=1.5f;
	
	public static float[][] yArray;
	public static int COLS;
	public static int ROWS;


	public static final float halfX=0.2f;//≥§∑ΩÃÂµƒ∞Î∏ﬂ∂»
	public static final float halfY=6f;//≥§∑ΩÃÂµƒ∞ÎøÌ∂»
	public static final float halfZ=4f;//≥§∑ΩÃÂµƒ∞Î≥§∂»
	public static final float groundHeight=-2f;//≥§∑ΩÃÂµƒ∞Î≥§∂»

	public static final float LEG_MASS=1f;//Õ»µƒ÷ ¡ø

	public static float cx=15;//…„œÒª˙Œª÷√XYZ◊¯±Í
	public static float cy=0;
	public static float cz=0;
	public static float yAngle=0;

	public static void initConstant(Resources r)
	{

		yArray=loadLandforms(r);
		COLS=yArray[0].length-1;
		ROWS=yArray.length-1;
		Log.e("initConstant" , "COLS > "+COLS +"  ROWS > "+ROWS) ;
	}
	

	public static float[][] loadLandforms(Resources resources)
	{
		Bitmap bt=BitmapFactory.decodeResource(resources, R.drawable.landform);
		int colsPlusOne=bt.getWidth();
		int rowsPlusOne=bt.getHeight(); 
		float[][] result=new float[rowsPlusOne][colsPlusOne];
		for(int i=0;i<rowsPlusOne;i++)
		{
			for(int j=0;j<colsPlusOne;j++)
			{
				int color=bt.getPixel(j,i);
				int r=Color.red(color);
				int g=Color.green(color); 
				int b=Color.blue(color);
				int h=(r+g+b)/3;
				result[i][j]=h*LAND_HIGHEST/255;  
			}
		}		
		return result;
	}


	public static final float cubeSize=1f;//≥§∑ΩÃÂµƒ∞Î∏ﬂ∂»

	public static final float Ball_R=1f;//≥§∑ΩÃÂµƒ∞Î≥§∂»
	public static final float Ball_Height=0f;//≥§∑ΩÃÂµƒ∞Î≥§∂»

	public static final float Stick_Length=5f;//≥§∑ΩÃÂµƒ∞Î≥§∂»
	public static final float Stick_R=0.2f;//≥§∑ΩÃÂµƒ∞Î≥§∂»
	public static final float Stick_Height=4f;//≥§∑ΩÃÂµƒ∞Î≥§∂»

	public static final float Ceiling_Height=8f;//≥§∑ΩÃÂµƒ∞Î≥§∂»
	public static final float Floor_Height=-2f;//≥§∑ΩÃÂµƒ∞Î≥§∂»

	static float Angle=0;
	public static final Vector3f boxPos = new Vector3f(-3,5,5);

	public  static boolean keyFlag=true;


	public static boolean isNumber(String str){
		if(str.equals("NaN") || Float.isInfinite(Float.parseFloat(str))){
			return false;
		}
		return true;
	}

}
